package com.intellagric.controller.module.trace_record;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.TraceRecordMonitor;
import com.intellagric.service.traceability.trace_record.MonitorRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/2/25
 * @DESC： 溯源监控设备管理
 */
@Controller
public class MonitorRecordController {

    @Autowired
    private MonitorRecordService monitorRecordService;

    /**
     * 添加溯源监控设备信息
     * @Param recordMonitor
     * @return ResponseMessage
     */
    @RequestMapping("/record/monitor/add")
    @ResponseBody
    public ResponseMessage add(TraceRecordMonitor recordMonitor) {
        recordMonitor.setId(UUID.randomUUID().toString().replaceAll("-",""));
        recordMonitor.setCreateDate(new Date());
        return monitorRecordService.addMonitorRecord(recordMonitor);
    }

    /**
     * 删除溯源监控设备信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/record/monitor/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return monitorRecordService.deleteIMonitorRecord(id);
    }

    /**
     * 修改溯源监控设备信息
     * @Param recordMonitor
     * @return ResponseMessage
     */
    @RequestMapping("/record/monitor/edit")
    @ResponseBody
    public ResponseMessage edit(TraceRecordMonitor recordMonitor) {
        return monitorRecordService.editMonitorRecord(recordMonitor);
    }

    /**
     * 查询溯源监控设备信息
     * @return TraceRecordMonitor
     */
    @RequestMapping("/record/monitor/{id}")
    @ResponseBody
    public TraceRecordMonitor get(@PathVariable String id) {
        return monitorRecordService.getMonitorRecordById(id);
    }

    /**
     * 查询溯源监控设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/monitor/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return monitorRecordService.getMonitorRecordList();
    }

    /**
     * 分页查询溯源监控设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/monitor/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return monitorRecordService.getMonitorRecordPage(page, limit);
    }

    /**
     * 多条件分页查询溯源监控设备信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/record/monitor/query")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,TraceRecordMonitor recordMonitor) {
        return monitorRecordService.getMonitorRecordPageByVo(page, limit,recordMonitor);
    }



}
